#基本的实现
#1,打开文件

# f = open('text.txt','r',encoding='utf-8')
#
# #2,读取文件
#
# file = f.read()
# print(file)

#3,关闭文件
# f.close()
"""中级实现"""
# try:
#     f = open('text.txt','r',encoding='utf-8')
#     file = f.read()
#     print(file)
# finally:
#     if f:
#         f.close()

"""最佳实践"""
# with open('text.txt','r',encoding='utf-8') as f:
#     file = f.read()
#     print(file)
#
# print(f.closed)

"""写入文件"""
# #1,打开文件(只写模式)
# f = open('test_hbq.txt','w',encoding='utf-8')
#
# #2,写入文件，写入内容
# content = '杭州今晚雨好大，怎么办，还打雷。'
# f.write(content)
# #3,关闭文件
# f.close()
# with open('test_hbq.txt','w',encoding='utf-8') as f:
#     content = '杭州今晚雨好大，怎么办，还打雷。'
#     f.write(content)
with open('test_hbq.txt','r',encoding='utf-8') as f:
    content = f.read()
print(content)

with open(r'D:\测试之道学院\代码\test_dao\文件读写' + 'test_hbq1.txt','w',encoding='utf-8') as f:
    f.write(content)

